package cn.bupt.adt.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class BeanUtil {
     static public void fatherToChild (Object father,Object child)throws Exception{  
        if(!(child.getClass().getSuperclass()==father.getClass())){  
            throw new Exception("child不是father的子类");  
        }  
        Class<? extends Object> fatherClass= father.getClass();  
        Field ff[]= fatherClass.getDeclaredFields();  
        for(int i=0;i<ff.length;i++){
        	Field f=ff[i];//取出每一个属性
        	f.setAccessible(true);
//            Class<?> type=f.getType();  
            Method m=fatherClass.getMethod("get"+upperHeadChar(f.getName()));//方法
            Object obj=m.invoke(father);//取出属性值                
            f.set(child,obj);  
        }  
    }  
/**
 * 
* @Title: beanToMap   
* @Description: (将该对象的内容以Map的形式返回)   
* @param @param 对象
* @param @return Map<String,Object>
* @param @throws IllegalArgumentException
* @param @throws IllegalAccessException    设定文件   
* @return Map<String,Object>    Map   
* @throws
 */
    public static Map<String,Object> beanToMap(Object bean) throws IllegalArgumentException, IllegalAccessException   {
    	Class<?> beanClass = bean.getClass();
    	Field[] beanFields = beanClass.getDeclaredFields();
    	Map<String,Object> map = new HashMap<>();
    	for(Field f:beanFields) {
//    		if(beanClass.getMethod(f.getName(), parameterTypes))
    		f.setAccessible(true);
    		map.put(f.getName(), f.get(bean));
    	}
    	return map;
    }
    static private String upperHeadChar(String in){
    	String head=in.substring(0,1);
    	String out = head.toUpperCase()+in.substring(1,in.length());
    	return out;
    }
    public  void t(){
    	
    }
    public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException, SecurityException {
	}
}


